(function($){
var timer_2,timer_1;
  var methods = {
    init : function( options ) { 
		// add a div to the DOM to receive the messages
		//console.log('Initialising Messaging');
	
		var config={};
		if (options) $.extend(config, options);

		$('body').append('<div id="message_s" class="message_s" style="display:none;position:absolute;z-index:100;background:black;padding:10px;"></div>');

	},
    show : function(message,options) {
		if(timer_2) { clearTimeout(timer_2); } 
		if(timer_1) { clearTimeout(timer_1); }
		// work out how wide it is
		var config={
			t_1:5000,
			t_2:3000
			
			};
		if (options) $.extend(config, options);
		
		var element=$("#message_s");
		element.css({height:'0px',width:'0px'}); // reset the fucking height because IE is a prick.
		element.html(message);
		var dims=element.hidden();
		var w=(dims.outerWidth<=400) ? 400 : dims.outerWidth;
		var l= ( $(window).width() - w ) / 2 +$(window).scrollLeft();
		var h=(dims.outerHeight<=150) ? 150 : dims.outerHeight;
		var t = ( $(window).height() - h ) / 2+$(window).scrollTop();
		
		element.show().css({'top':'0px','left':l+'px','width':w+'px','height':(h)+'px'}).animate({'top':t+'px','opacity':0.9},300);
		/* After 5 seconds hide it */
		timer_2=setTimeout("$.fn.message('hide')",config.t_1);
		timer_1=setTimeout("$.fn.message('bindEvts')", config.t_2);
	},
    hide : function( ) {
		var element=$("#message_s");
		//var h=$(window).height();
		element.animate({top:'0px',opacity:0},300,function(){element.html("")});
	},
    update : function( content ) {  
	
	},
	bindEvts: function() {
	// Remove message if mouse is moved or key is pressed
		$(window).mousemove($.fn.message('hide')).click($.fn.message('hide')).keypress($.fn.message('hide')); //;
	},
	removeMsg: function() {
		$(window).unbind('mousemove',$.fn.message('hide')).unbind('click',$.fn.message('hide')).unbind('keypress',$.fn.message('hide'));	
	}
  };

  $.fn.message = function( method ) {
    
    // Method calling logic
    if ( methods[method] ) {
      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    } else {
     // $.error( 'Method ' +  method + ' does not exist on jQuery.tooltip' );
   	return false;
    }    
  
  };

})( jQuery );
